#include "userFunctions.h"

template<unsigned int dim>
Tensor<1,dim,double> uinit(const Tensor<1,dim,double> &x, unsigned int vector_i, AppCtx<dim> &user){
  Tensor<1,dim,double> tmp; 
  for (int i=0; i<dim; i++) 
  {
      tmp[i]=0;
  }
  if ( (x[0]-0.5)*(x[0]-0.5)+(x[1]-0.5)*(x[1]-0.5)+(x[2]-0.5)*(x[2]-0.5) < 0.1 ) tmp[0]=2.e-3;
  return tmp;
}; //end uinit

template<unsigned int dim>
void projectFields(const Tensor<1,dim,double> &x,
		   const Tensor<1,dim,double> &normal,
		   const solutionScalars<dim,double> &c,
		   const solutionVectors<dim,double> &u,
		   AppCtx<dim> &user,
		   std::vector<double> &scalarProjections,
		   std::vector<Tensor<1,dim,double> > &vectorProjections){
} //end projectFields

template<unsigned int dim>
void defineParameters(AppCtx<dim>& user){

  user.periodic[0] = PETSC_TRUE;
  user.periodic[1] = PETSC_TRUE;
  user.periodic[2] = PETSC_TRUE;
 
  user.N[0] = 4;
  user.N[1] = 4;
  user.N[2] = 4;
  user.L[0] = 1.;
  user.L[1] = 1.;
  user.L[2] = 1.;

  user.vectorSolnFields.push_back("displacement");
  user.scalarProjectnFields.push_back("");

  user.polyOrder = 2;
  user.globalContinuity = 1;

  user.vectorInitialConditions = uinit;

    user.par_mat=(double *) malloc(9*sizeof(double));
    user.par_mat[0]=0.25;
    user.par_mat[1]=0.50;
    user.par_mat[2]=500.;
    user.par_mat[3]=250.;
    user.par_mat[4]=0.025;
    user.par_mat[5]=1.0;
    user.par_mat[6]=1.0;
    user.par_mat[7]=1.e-3*(1./2.);
    user.par_mat[8]=0.0;

} //end defineParameters


template <typename T>
void eval_residual(T *residual, T *u, double *par);

template<unsigned int dim, typename T>
void residual(bool dV,
	      bool dS,
              const Tensor<1,dim,double> &x,
	      const Tensor<1,dim,double> &normal,
	      const solutionScalars<dim,T> &c,
	      const solutionVectors<dim,T> &u,
	      const testFunctionScalars<dim,T> &w1,
	      const testFunctionVectors<dim,T> &w2,
	      AppCtx<dim> &user,
	      Sacado::Fad::SimpleFad<T> &r){
  int ndim=dim;
  int ndof=3;
  int nddim=1+ndim+ndim*(ndim+1)/2;
  T ui[]={ u.val(0)[0], u.grad(0)[0][0], u.grad(0)[0][1], u.grad(0)[0][2], u.hess(0)[0][0][0], u.hess(0)[0][0][1], u.hess(0)[0][0][2], u.hess(0)[0][1][1], u.hess(0)[0][1][2], u.hess(0)[0][2][2],
           u.val(0)[1], u.grad(0)[1][0], u.grad(0)[1][1], u.grad(0)[1][2], u.hess(0)[1][0][0], u.hess(0)[1][0][1], u.hess(0)[1][0][2], u.hess(0)[1][1][1], u.hess(0)[1][1][2], u.hess(0)[1][2][2],
           u.val(0)[2], u.grad(0)[2][0], u.grad(0)[2][1], u.grad(0)[2][2], u.hess(0)[2][0][0], u.hess(0)[2][0][1], u.hess(0)[2][0][2], u.hess(0)[2][1][1], u.hess(0)[2][1][2], u.hess(0)[2][2][2] };
  double 
    u0[]={ u.valP(0)[0], u.gradP(0)[0][0], u.gradP(0)[0][1], u.gradP(0)[0][2], u.hessP(0)[0][0][0], u.hessP(0)[0][0][1], u.hessP(0)[0][0][2], u.hessP(0)[0][1][1], u.hessP(0)[0][1][2], u.hessP(0)[0][2][2],
           u.valP(0)[1], u.gradP(0)[1][0], u.gradP(0)[1][1], u.gradP(0)[1][2], u.hessP(0)[1][0][0], u.hessP(0)[1][0][1], u.hessP(0)[1][0][2], u.hessP(0)[1][1][1], u.hessP(0)[1][1][2], u.hessP(0)[1][2][2],
           u.valP(0)[2], u.gradP(0)[2][0], u.gradP(0)[2][1], u.gradP(0)[2][2], u.hessP(0)[2][0][0], u.hessP(0)[2][0][1], u.hessP(0)[2][0][2], u.hessP(0)[2][1][1], u.hessP(0)[2][1][2], u.hessP(0)[2][2][2] };
  Sacado::Fad::SimpleFad<T> 
    w[]= { w2.val(0)[0], w2.grad(0)[0][0], w2.grad(0)[0][1], w2.grad(0)[0][2], w2.hess(0)[0][0][0], w2.hess(0)[0][0][1], w2.hess(0)[0][0][2], w2.hess(0)[0][1][1], w2.hess(0)[0][1][2], w2.hess(0)[0][2][2],
           w2.val(0)[1], w2.grad(0)[1][0], w2.grad(0)[1][1], w2.grad(0)[1][2], w2.hess(0)[1][0][0], w2.hess(0)[1][0][1], w2.hess(0)[1][0][2], w2.hess(0)[1][1][1], w2.hess(0)[1][1][2], w2.hess(0)[1][2][2],
           w2.val(0)[2], w2.grad(0)[2][0], w2.grad(0)[2][1], w2.grad(0)[2][2], w2.hess(0)[2][0][0], w2.hess(0)[2][0][1], w2.hess(0)[2][0][2], w2.hess(0)[2][1][1], w2.hess(0)[2][1][2], w2.hess(0)[2][2][2] };
  T residual[ndof*nddim];
  eval_residual(residual,ui,user.par_mat);
  r=0;
  for (int i=0; i<nddim*ndof; ++i) { r+=w[i]*residual[i]; }
  r*=dV;
  //r += -(w2.val(0)*h)*dS; //Traction

} //end residual

template <typename T>
void eval_residual(T *residual_, T *u, double *par)
{
T e[39];
*(e+0)=(-1 + pow(1 + (*(u+1)),2) + pow((*(u+11)),2) + pow((*(u+21)),2))/2.;
*(e+1)=((1 + (*(u+1)))*(*(u+2)) + (*(u+11))*(1 + (*(u+12))) + (*(u+21))*(*(u+22)))/2.;
*(e+2)=((1 + (*(u+1)))*(*(u+3)) + (*(u+11))*(*(u+13)) + (*(u+21))*(1 + (*(u+23))))/2.;
*(e+3)=(-1 + pow((*(u+2)),2) + pow(1 + (*(u+12)),2) + pow((*(u+22)),2))/2.;
*(e+4)=((*(u+2))*(*(u+3)) + (1 + (*(u+12)))*(*(u+13)) + (*(u+22))*(1 + (*(u+23))))/2.;
*(e+5)=(-1 + pow((*(u+3)),2) + pow((*(u+13)),2) + pow(1 + (*(u+23)),2))/2.;
*(e+6)=(2*(1 + (*(u+1)))*(*(u+4)) + 2*(*(u+11))*(*(u+14)) + 2*(*(u+21))*(*(u+24)))/2.;
*(e+7)=(2*(1 + (*(u+1)))*(*(u+5)) + 2*(*(u+11))*(*(u+15)) + 2*(*(u+21))*(*(u+25)))/2.;
*(e+8)=(2*(1 + (*(u+1)))*(*(u+6)) + 2*(*(u+11))*(*(u+16)) + 2*(*(u+21))*(*(u+26)))/2.;
*(e+9)=((*(u+2))*(*(u+4)) + (1 + (*(u+1)))*(*(u+5)) + (1 + (*(u+12)))*(*(u+14)) + (*(u+11))*(*(u+15)) + (*(u+22))*(*(u+24)) + (*(u+21))*(*(u+25)))/2.;
*(e+10)=((*(u+2))*(*(u+5)) + (1 + (*(u+1)))*(*(u+7)) + (1 + (*(u+12)))*(*(u+15)) + (*(u+11))*(*(u+17)) + (*(u+22))*(*(u+25)) + (*(u+21))*(*(u+27)))/2.;
*(e+11)=((*(u+2))*(*(u+6)) + (1 + (*(u+1)))*(*(u+8)) + (1 + (*(u+12)))*(*(u+16)) + (*(u+11))*(*(u+18)) + (*(u+22))*(*(u+26)) + (*(u+21))*(*(u+28)))/2.;
*(e+12)=((*(u+3))*(*(u+4)) + (1 + (*(u+1)))*(*(u+6)) + (*(u+13))*(*(u+14)) + (*(u+11))*(*(u+16)) + (1 + (*(u+23)))*(*(u+24)) + (*(u+21))*(*(u+26)))/2.;
*(e+13)=((*(u+3))*(*(u+5)) + (1 + (*(u+1)))*(*(u+8)) + (*(u+13))*(*(u+15)) + (*(u+11))*(*(u+18)) + (1 + (*(u+23)))*(*(u+25)) + (*(u+21))*(*(u+28)))/2.;
*(e+14)=((*(u+3))*(*(u+6)) + (1 + (*(u+1)))*(*(u+9)) + (*(u+13))*(*(u+16)) + (*(u+11))*(*(u+19)) + (1 + (*(u+23)))*(*(u+26)) + (*(u+21))*(*(u+29)))/2.;
*(e+15)=(2*(*(u+2))*(*(u+5)) + 2*(1 + (*(u+12)))*(*(u+15)) + 2*(*(u+22))*(*(u+25)))/2.;
*(e+16)=(2*(*(u+2))*(*(u+7)) + 2*(1 + (*(u+12)))*(*(u+17)) + 2*(*(u+22))*(*(u+27)))/2.;
*(e+17)=(2*(*(u+2))*(*(u+8)) + 2*(1 + (*(u+12)))*(*(u+18)) + 2*(*(u+22))*(*(u+28)))/2.;
*(e+18)=((*(u+3))*(*(u+5)) + (*(u+2))*(*(u+6)) + (*(u+13))*(*(u+15)) + (1 + (*(u+12)))*(*(u+16)) + (1 + (*(u+23)))*(*(u+25)) + (*(u+22))*(*(u+26)))/2.;
*(e+19)=((*(u+3))*(*(u+7)) + (*(u+2))*(*(u+8)) + (*(u+13))*(*(u+17)) + (1 + (*(u+12)))*(*(u+18)) + (1 + (*(u+23)))*(*(u+27)) + (*(u+22))*(*(u+28)))/2.;
*(e+20)=((*(u+3))*(*(u+8)) + (*(u+2))*(*(u+9)) + (*(u+13))*(*(u+18)) + (1 + (*(u+12)))*(*(u+19)) + (1 + (*(u+23)))*(*(u+28)) + (*(u+22))*(*(u+29)))/2.;
*(e+21)=(2*(*(u+3))*(*(u+6)) + 2*(*(u+13))*(*(u+16)) + 2*(1 + (*(u+23)))*(*(u+26)))/2.;
*(e+22)=(2*(*(u+3))*(*(u+8)) + 2*(*(u+13))*(*(u+18)) + 2*(1 + (*(u+23)))*(*(u+28)))/2.;
*(e+23)=(2*(*(u+3))*(*(u+9)) + 2*(*(u+13))*(*(u+19)) + 2*(1 + (*(u+23)))*(*(u+29)))/2.;
*(e+24)=((*(e+0)) + (*(e+3)) + (*(e+5)))/sqrt(3);
*(e+25)=((*(e+0)) - (*(e+3)))/sqrt(2);
*(e+26)=((*(e+0)) + (*(e+3)) - 2*(*(e+5)))/sqrt(6);
*(e+27)=((*(e+6)) + (*(e+15)) + (*(e+21)))/sqrt(3);
*(e+28)=((*(e+7)) + (*(e+16)) + (*(e+22)))/sqrt(3);
*(e+29)=((*(e+8)) + (*(e+17)) + (*(e+23)))/sqrt(3);
*(e+30)=((*(e+6)) - (*(e+15)))/sqrt(2);
*(e+31)=((*(e+7)) - (*(e+16)))/sqrt(2);
*(e+32)=((*(e+8)) - (*(e+17)))/sqrt(2);
*(e+33)=((*(e+6)) + (*(e+15)) - 2*(*(e+21)))/sqrt(6);
*(e+34)=((*(e+7)) + (*(e+16)) - 2*(*(e+22)))/sqrt(6);
*(e+35)=((*(e+8)) + (*(e+17)) - 2*(*(e+23)))/sqrt(6);
*(e+36)=-((1.3333333333333333*(*(par+0)) - 1.3333333333333333*(*(par+0))*(*(par+1)))/(pow((*(par+0)),2)*(pow((*(par+0)),2) - 2*pow((*(par+0)),2)*(*(par+1)) - (*(par+0))*(1.3333333333333333*(*(par+0)) - 1.3333333333333333*(*(par+0))*(*(par+1))))));
*(e+37)=(2*(*(par+1)))/(pow((*(par+0)),2) - 2*pow((*(par+0)),2)*(*(par+1)) - (*(par+0))*(1.3333333333333333*(*(par+0)) - 1.3333333333333333*(*(par+0))*(*(par+1))));
*(e+38)=-(1/(pow((*(par+0)),2)*(pow((*(par+0)),2) - 2*pow((*(par+0)),2)*(*(par+1)) - (*(par+0))*(1.3333333333333333*(*(par+0)) - 1.3333333333333333*(*(par+0))*(*(par+1))))));
*(residual_+0)=0;
*(residual_+1)=((-6*(*(e+25))*(*(e+26))*(*(e+36)) + 2*(*(e+25))*(*(e+37)) + 4*(*(e+25))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(1 + (*(u+1))))/sqrt(2) + ((2*pow((*(e+26)),2)*(*(e+36)) + (-3*pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+36)) + 2*(*(e+26))*(*(e+37)) + 4*(*(e+26))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(1 + (*(u+1))))/sqrt(6) + (2*(*(e+24))*(*(par+2))*(1 + (*(u+1))))/sqrt(3) + (*(e+1))*(*(par+3))*(*(u+2)) + (*(e+2))*(*(par+3))*(*(u+3)) + sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+4)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+4)) + sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+5)) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+5)) + sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+6)) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+6));
*(residual_+2)=(*(e+1))*(*(par+3))*(1 + (*(u+1))) - ((-6*(*(e+25))*(*(e+26))*(*(e+36)) + 2*(*(e+25))*(*(e+37)) + 4*(*(e+25))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+2)))/sqrt(2) + ((2*pow((*(e+26)),2)*(*(e+36)) + (-3*pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+36)) + 2*(*(e+26))*(*(e+37)) + 4*(*(e+26))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+2)))/sqrt(6) + (2*(*(e+24))*(*(par+2))*(*(u+2)))/sqrt(3) + (*(e+4))*(*(par+3))*(*(u+3)) - sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+5)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+5)) - sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+7)) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+7)) - sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+8)) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+8));
*(residual_+3)=(*(e+2))*(*(par+3))*(1 + (*(u+1))) + (*(e+4))*(*(par+3))*(*(u+2)) - sqrt(0.6666666666666666)*(2*pow((*(e+26)),2)*(*(e+36)) + (-3*pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+36)) + 2*(*(e+26))*(*(e+37)) + 4*(*(e+26))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+3)) + (2*(*(e+24))*(*(par+2))*(*(u+3)))/sqrt(3) - 2*sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+6)) - 2*sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+8)) - 2*sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+9));
*(residual_+4)=sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(1 + (*(u+1))) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(1 + (*(u+1)));
*(residual_+5)=sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(1 + (*(u+1))) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(1 + (*(u+1))) - sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+2)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+2));
*(residual_+6)=sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(1 + (*(u+1))) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(1 + (*(u+1))) - 2*sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+3));
*(residual_+7)=-(sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+2))) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+2));
*(residual_+8)=-(sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+2))) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+2)) - 2*sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+3));
*(residual_+9)=-2*sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+3));
*(residual_+10)=0;
*(residual_+11)=((-6*(*(e+25))*(*(e+26))*(*(e+36)) + 2*(*(e+25))*(*(e+37)) + 4*(*(e+25))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+11)))/sqrt(2) + ((2*pow((*(e+26)),2)*(*(e+36)) + (-3*pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+36)) + 2*(*(e+26))*(*(e+37)) + 4*(*(e+26))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+11)))/sqrt(6) + (2*(*(e+24))*(*(par+2))*(*(u+11)))/sqrt(3) + (*(e+1))*(*(par+3))*(1 + (*(u+12))) + (*(e+2))*(*(par+3))*(*(u+13)) + sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+14)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+14)) + sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+15)) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+15)) + sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+16)) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+16));
*(residual_+12)=(*(e+1))*(*(par+3))*(*(u+11)) - ((-6*(*(e+25))*(*(e+26))*(*(e+36)) + 2*(*(e+25))*(*(e+37)) + 4*(*(e+25))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(1 + (*(u+12))))/sqrt(2) + ((2*pow((*(e+26)),2)*(*(e+36)) + (-3*pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+36)) + 2*(*(e+26))*(*(e+37)) + 4*(*(e+26))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(1 + (*(u+12))))/sqrt(6) + (2*(*(e+24))*(*(par+2))*(1 + (*(u+12))))/sqrt(3) + (*(e+4))*(*(par+3))*(*(u+13)) - sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+15)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+15)) - sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+17)) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+17)) - sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+18)) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+18));
*(residual_+13)=(*(e+2))*(*(par+3))*(*(u+11)) + (*(e+4))*(*(par+3))*(1 + (*(u+12))) - sqrt(0.6666666666666666)*(2*pow((*(e+26)),2)*(*(e+36)) + (-3*pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+36)) + 2*(*(e+26))*(*(e+37)) + 4*(*(e+26))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+13)) + (2*(*(e+24))*(*(par+2))*(*(u+13)))/sqrt(3) - 2*sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+16)) - 2*sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+18)) - 2*sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+19));
*(residual_+14)=sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+11)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+11));
*(residual_+15)=sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+11)) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+11)) - sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(1 + (*(u+12))) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(1 + (*(u+12)));
*(residual_+16)=sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+11)) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+11)) - 2*sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+13));
*(residual_+17)=-(sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(1 + (*(u+12)))) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(1 + (*(u+12)));
*(residual_+18)=-(sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(1 + (*(u+12)))) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(1 + (*(u+12))) - 2*sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+13));
*(residual_+19)=-2*sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+13));
*(residual_+20)=0;
*(residual_+21)=((-6*(*(e+25))*(*(e+26))*(*(e+36)) + 2*(*(e+25))*(*(e+37)) + 4*(*(e+25))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+21)))/sqrt(2) + ((2*pow((*(e+26)),2)*(*(e+36)) + (-3*pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+36)) + 2*(*(e+26))*(*(e+37)) + 4*(*(e+26))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+21)))/sqrt(6) + (2*(*(e+24))*(*(par+2))*(*(u+21)))/sqrt(3) + (*(e+1))*(*(par+3))*(*(u+22)) + (*(e+2))*(*(par+3))*(1 + (*(u+23))) + sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+24)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+24)) + sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+25)) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+25)) + sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+26)) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+26));
*(residual_+22)=(*(e+1))*(*(par+3))*(*(u+21)) - ((-6*(*(e+25))*(*(e+26))*(*(e+36)) + 2*(*(e+25))*(*(e+37)) + 4*(*(e+25))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+22)))/sqrt(2) + ((2*pow((*(e+26)),2)*(*(e+36)) + (-3*pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+36)) + 2*(*(e+26))*(*(e+37)) + 4*(*(e+26))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(*(u+22)))/sqrt(6) + (2*(*(e+24))*(*(par+2))*(*(u+22)))/sqrt(3) + (*(e+4))*(*(par+3))*(1 + (*(u+23))) - sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+25)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+25)) - sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+27)) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+27)) - sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+28)) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+28));
*(residual_+23)=(*(e+2))*(*(par+3))*(*(u+21)) + (*(e+4))*(*(par+3))*(*(u+22)) - sqrt(0.6666666666666666)*(2*pow((*(e+26)),2)*(*(e+36)) + (-3*pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+36)) + 2*(*(e+26))*(*(e+37)) + 4*(*(e+26))*(pow((*(e+25)),2) + pow((*(e+26)),2))*(*(e+38)))*(1 + (*(u+23))) + (2*(*(e+24))*(*(par+2))*(1 + (*(u+23))))/sqrt(3) - 2*sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+26)) - 2*sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+28)) - 2*sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+29));
*(residual_+24)=sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+21)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+21));
*(residual_+25)=sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+21)) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+21)) - sqrt(2)*(*(e+30))*pow((*(par+4)),2)*(*(u+22)) + sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(*(u+22));
*(residual_+26)=sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+21)) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+21)) - 2*sqrt(0.6666666666666666)*(*(e+33))*pow((*(par+4)),2)*(1 + (*(u+23)));
*(residual_+27)=-(sqrt(2)*(*(e+31))*pow((*(par+4)),2)*(*(u+22))) + sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(*(u+22));
*(residual_+28)=-(sqrt(2)*(*(e+32))*pow((*(par+4)),2)*(*(u+22))) + sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(*(u+22)) - 2*sqrt(0.6666666666666666)*(*(e+34))*pow((*(par+4)),2)*(1 + (*(u+23)));
*(residual_+29)=-2*sqrt(0.6666666666666666)*(*(e+35))*pow((*(par+4)),2)*(1 + (*(u+23)));
}
#include "userFunctionsInstantiation.h"
